<?php

//include_once '../../data/config.php';
//include_once '../../data/DBConn.php';

	require_once ($_SERVER['DOCUMENT_ROOT']."/Auditing/data/config.php");
	require_once ($_SERVER['DOCUMENT_ROOT']."/Auditing/data/DBConn.php");

 Class RetrieveRules{
 	
 	function RetrieveRules(){
 		
 		
 	}
 	
 	function getData($rule_desc,$rule_meta_data_id){
 		$rule_val;
 		
 		if($rule_desc!=""){
 			$rule_val = " AND meta.rule_meta_data_id = rule.".$rule_desc;
 		} else {
 			
 			$rule_val = " AND meta.rule_meta_data_id = ".$rule_meta_data_id;
 		}
 			
 		$sqlString = " select meta.description, ota_flag.description,  ota_field.description, ota_logic.description,rule.value,meta.rule_meta_data_id ".
					" from ota_rulemetadata meta, ota_ruleset rule, ota_field ,ota_logic, ota_flag ".
					" where  ".
					" meta.flag_id = ota_flag.flag_id ".
					" AND rule.logic_id = ota_logic.logic_id ".
					" AND rule.field_id = ota_field.field_id  ".
					" AND meta.rule_meta_data_id = rule.rule_meta_data_id ".
					$rule_val.
					" ORDER BY rule.rule ";
 		
		//echo $sqlString;
		
 		
 		$result = mysql_query($sqlString);
        $td="";   
          
		 if (!$result) {
		    die	('Invalid query: ' . mysql_error());
		}else {
			
			
			$i=1;
			$evenClass ="TableRowEven";
			$oddClass ="TableRowOdd";
			
			//$anchor = "<a href='../../view/Rule/RuleCreate.php'>";
				
			while ($row = mysql_fetch_array($result)) {

				if($i%2==0){
					$classSel="TableRowEven";
				}else {
					$classSel="TableRowOdd";
				}
				
				
				$td .= "<tr>";
				$td .= "<td class='".$classSel."' >". $i ."</td>";
				$td .= "<td class='".$classSel."' >". $row[0] . "</td>";
				$td .= "<td class='".$classSel."' >". $row[1] . "</td>";
				$td .= "<td class='".$classSel."' >". $row[2] . "</td>";
				$td .= "<td class='".$classSel."' >". $row[3] . "</td>";
				$td .= "<td class='".$classSel."' >". $row[4] . "</td>";
				$anchor = "<a href='../../view/Rule/RuleCreate.php?operation=update&rule_meta_data_id=".$row[5]."'>";
				$td .= "<td class='".$classSel."' >".$anchor. Edit . "</a></td>";
				$td .= "</tr>";
				$i++;
			}

		}
	return $td;
 	}
 	
 	function viewRulesData($rule_meta_data_id){
 		
 		$sqlString = " select meta.description, ota_flag.flag_id, ".  
					" ota_field.field_id, ota_logic.logic_id,".
					" rule.value ".
					" from rulemetadata meta, ruleset rule, ota_field ,ota_logic, ota_flag ".
					" where  ".
					" meta.flag_id = ota_flag.flag_id ".
					" and rule.logic_id = ota_logic.logic_id ".
					" and rule.field_id = ota_field.field_id  ".
					" and meta.rule_meta_data_id = rule.rule_meta_data_id ".
					" and meta.rule_meta_data_id = ".$rule_meta_data_id.
					" order by rule.rule ";

	//	echo $sqlString;
		
		$result = mysql_query($sqlString);
             
		 if (!$result) {
		   die	('Invalid query: ' . mysql_error());
		 }//else {			
		$html="";	
		
		$counter=1;
			
 	return $result;
 	
	}
 }
?>